package com.itheima.service.impl;


import com.itheima.entity.Dept;
import com.itheima.mapper.DeptMapper;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


/**
 * 业务逻辑处理层
 * 用于逻辑处理
 */
//@Component//程序启动时，会自动创建该类对象，并交由IOC容器管理
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired//从IOC容器中，自当寻找bean对象，为该变量赋值
    private DeptMapper deptMapper;

    //查询部门列表
    @Override
    public List<Dept> list() {
        //调用mapper的方法获取列表数据
        return deptMapper.list();
    }

    //根据id删除部门信息
    @Override
    public void delete(Integer id) {
        //调用mapper的删除方法
        deptMapper.delete(id);
    }

    @Override
    public void add(Dept dept) {
        //补充基础属性
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.add(dept);
    }

    @Override
    public Dept getById(Integer id) {

        return deptMapper.getById(id);
    }

    @Override
    public void update(Dept dept) {

        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }
}